package com.scau.beyondboy.services.impl;
import com.scau.beyondboy.dao.BaseDao;
import com.scau.beyondboy.dao.UserDao;
import com.scau.beyondboy.dao.impl.UserDaoImpl;
import com.scau.beyondboy.model.UserEntity;
import com.scau.beyondboy.services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
/**
 * Author:beyondboy
 * Gmail:xuguoli.scau@gmail.com
 * Date: 2015/12/11
 * Time: 0:48
 */
@Service(value = "userService")
//@Transactional(readOnly = false)
public class UserServicesImpl extends BaseServiceImpl<UserEntity> implements UserServices
{
    @Autowired
    private UserDao userDao;

    @Resource(name = "userDao")
    public void setDao(BaseDao<UserEntity> dao){
        super.setDao(dao);
        userDao = (UserDao)dao;
    }
    @Override
    public boolean checkLogin(String username, String password)
    {
        List<UserEntity> list = userDao.checkUser(username,password);
        if(list.size()!=0)
        {
            return true;
        }
        return false;
    }
    @Override
    public boolean addUser(String username, String password)
    {
        System.out.println("username = [" + username + "], password = [" + password + "]");
        List<UserEntity> list = userDao.findUser(username);
        System.out.println("长度：  "+list.size());
        if(list.size()!=0)
        {
            return false;
        }
        else
        {
            System.out.println("username = [" + username + "], password = [" + password + "]");
            UserEntity userEntity=new UserEntity();
            userEntity.setUsername(username);
            userEntity.setPassword(password);
            userDao.addUser(username,password);
           // userDao.save(userEntity);
            //userDao.flush();
            return true;
        }
    }
}
